package configs

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type ConfigType struct {
	MysqlUsername string
	MysqlPassword string
	MysqlAddress  string
	MysqlDatabase string
	MysqlEnv      string
	MysqlDSN      string

	ServerAddress string

	Secret             string
	TokenLiveTime      int
	RedisTokenLiveTime int

	RedisAddress  []string
	RedisPassword string
}

func (t *ConfigType) Init() {
	t.MysqlDSN = t.MysqlUsername + ":" + t.MysqlPassword + "@tcp(" + t.MysqlAddress + ")/" + t.MysqlDatabase + t.MysqlEnv
}

var Config = &ConfigType{}

func InitConfig() {
	data, _ := ioutil.ReadFile("config.yml")
	err := yaml.Unmarshal(data, &Config)
	Config.Init()

	if err != nil {
		panic(err)
	}
}
